package logic

import (
	"context"
	"github.com/jinzhu/copier"
	"hzjt-oam/rpc/sys/internal/svc"
	"hzjt-oam/rpc/sys/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSysUserByIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetSysUserByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSysUserByIdLogic {
	return &GetSysUserByIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetSysUserByIdLogic) GetSysUserById(in *pb.GetSysUserByIdReq) (*pb.GetSysUserByIdResp, error) {
	one, err := l.svcCtx.UserModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}
	var sys_user = &pb.SysUser{}
	if err := copier.Copy(sys_user, one); err != nil {
		return nil, err
	}
	dept_one, err := l.svcCtx.DeptModel.FindOne(l.ctx, one.DeptId)
	if err != nil {
		return nil, err
	}
	role_one, err := l.svcCtx.RoleModel.FindOne(l.ctx, one.RoleId)
	sys_user.DeptName = dept_one.Name
	sys_user.RoleName = role_one.Name
	return &pb.GetSysUserByIdResp{SysUser: sys_user}, nil
}
